extends Node


@onready var unit_action_ui: UnitActionUI = %UnitActionUI
@onready var input_manager: InputManager = %InputManager
@onready var move_manager: MoveManager = %MoveManager
@onready var attack_manager: AttackManager = %AttackManager



func _on_select_unit_action_state_entered() -> void:
	unit_action_ui.show_ui()


func _on_moving_state_entered() -> void:
	if not move_manager.move_target_cell:
		push_error("没有移动目的地坐标")
		%GameStateMachine.send_event("toGameBase")
	var chosen_unit: Player = input_manager.player_chosen
	await move_manager.move_character_to(chosen_unit)
	%GameStateMachine.send_event("toGameBase")


func _on_base_state_state_entered() -> void:
	unit_action_ui.visible = false
	input_manager.player_chosen = null
	move_manager.clear_move_preview()


func _on_wait_to_move_state_entered() -> void:
	unit_action_ui.visible = false
	var chosen_unit: Player = input_manager.player_chosen
	move_manager.show_move_preview(chosen_unit)


func _on_target_state_entered() -> void:
	attack_manager.attack_target_start(input_manager.player_chosen)
